//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
/// @file TextureBase.h
///
///
/// @author Davide Pasca
///
//==================================================================

#ifndef TEXTUREBASE_H
#define TEXTUREBASE_H

#if defined(TARGET_D3D)
	#include <direct3d.h>
#endif

#include "psys.h"
#include "image_base.h"

//==================================================================
class TextureBase
{
	bool				_owns_image_base;
	bool				_owns_texture_object;
	bool				_is_hardware_only;
	PUtils::ImageBase	*_image_basep;
	int					_w2, _h2;
	float				_scoe, _tcoe;
	class RendDevice	*_rdevicep;

public:
#if defined(TARGET_D3D)
	D3DTexture			_d3dtex_cp;
	
#elif defined(TARGET_OPENGL)
	u_int				_tex_ogl_id;
#else
	#error "Unknown target !!!"
#endif

public:
	//--------------------------------------------------------------
	TextureBase( PUtils::ImageBase *image_basep, class RendDevice *rdevicep );
	TextureBase( const TCHAR *filenamep, PUtils::ImageBase::LoadParams *paramsp, class RendDevice *rdevicep );
	TextureBase( u_int w, u_int h, class RendDevice *rdevicep );
	virtual ~TextureBase();
//	void		SetDevice( RendDevice *rdevicep ){ _rdevicep = rdevicep; }
	//--------------------------------------------------------------
	void				LoadTexture( const TCHAR *filenamep, PUtils::ImageBase::LoadParams *paramsp=NULL ) throw(...);
	void				SelectTexture();

	float				GetSTexRatio() const	{ return _scoe; }
	float				GetTTexRatio() const	{ return _tcoe; }

	PUtils::ImageBase	*GetImageBase()				{ return _image_basep; }
	const PUtils::ImageBase	*GetImageBase() const	{ return _image_basep; }

#if defined(TARGET_D3D)
	void				SetTextureObject( D3DTexture *d3dtex_cp )
	{
		PASSERT( !_owns_texture_object );
		_d3dtex_cp = d3dtex_cp;
	}

#elif defined(TARGET_OPENGL)
	void				SetTextureObject( int tex_ogl_id )
	{
		PASSERT( !_owns_texture_object );
		_tex_ogl_id = tex_ogl_id;
	}
#endif

	void UpdateTexture()
	{
		uploadTexture();
		onSizeChange();
	}

private:
	bool		uploadTexture();
	void		onSizeChange();
};

#endif
